home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.004 / xemacs-1 / xemacs-19.13 / src / dynarr.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-17  |  2.5 KB  |  69 lines

  1. /* Simple 'n' stupid dynamic-array module -- include file.
  2.    Copyright (C) 1993 Sun Microsystems, Inc.
  3.  
  4. This file is part of XEmacs.
  5.  
  6. XEmacs is free software; you can redistribute it and/or modify it
  7. under the terms of the GNU General Public License as published by the
  8. Free Software Foundation; either version 2, or (at your option) any
  9. later version.
  10.  
  11. XEmacs is distributed in the hope that it will be useful, but WITHOUT
  12. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14. for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with XEmacs; see the file COPYING.  If not, write to the Free
  18. Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
  19.  
  20. /* Synched up with: Not in FSF. */
  21.  
  22. /* Written by Ben Wing, December 1993. */
  23.  
  24. #ifndef _XEMACS_DYNARR_H_
  25. #define _XEMACS_DYNARR_H_
  26.  
  27. #define Dynarr_declare(type)                                         \
  28.   type *base;                                                        \
  29.   int elsize;                                                        \
  30.   int cur;                                                           \
  31.   int largest;                                 \
  32.   int max
  33.  
  34. typedef struct dynarr
  35. {
  36.   Dynarr_declare (void);
  37. } Dynarr;
  38.  
  39. void *Dynarr_newf (int elsize);
  40. void Dynarr_resize (void *dy, int size);
  41. void Dynarr_insert_many (void *d, void *el, int len, int start);
  42. void Dynarr_delete_many (void *d, int start, int len);
  43. void Dynarr_free (void *d);
  44.  
  45. #define Dynarr_new(type) Dynarr_newf (sizeof(* (type *) NULL))
  46. #define Dynarr_at(d, pos) ((d)->base[pos])
  47. #define Dynarr_atp(d, pos) (&Dynarr_at (d, pos))
  48. #define Dynarr_length(d) ((d)->cur)
  49. #define Dynarr_largest(d) ((d)->largest)
  50. #define Dynarr_reset(d) ((d)->cur = 0)
  51. #define Dynarr_add_many(d, el, len) Dynarr_insert_many (d, el, len, (d)->cur)
  52. #define Dynarr_insert_many_at_start(d, el, len)                \
  53.   Dynarr_insert_many (d, el, len, 0)
  54.  
  55. #define Dynarr_add(d, el) (                        \
  56.   (d)->cur >= (d)->max ? Dynarr_resize ((d), (d)->cur+1) : (void) 0,    \
  57.   ((d)->base)[(d)->cur++] = (el),                    \
  58.   (d)->cur > (d)->largest ? (d)->largest = (d)->cur : (int) 0)
  59.  
  60. /* The following defines will get you into real trouble if you aren't
  61.    careful.  But they can save a lot of execution time when used wisely. */
  62. #define Dynarr_increment(d) ((d)->cur++)
  63. #define Dynarr_set_size(d, n) ((d)->cur = n)
  64.  
  65. /* Minimum size in elements for dynamic array when resized; default is 32 */
  66. extern int Dynarr_min_size;
  67.  
  68. #endif /* _XEMACS_DYNARR_H_ */
  69.